package com.hubu.blog.entity.table;

import com.mybatisflex.core.query.QueryColumn;
import com.mybatisflex.core.table.TableDef;

import java.io.Serial;

/**
 * 博客用户表 表定义层。
 *
 * @author 331126135@qq.com
 * @since 2025-06-10
 */
public class UserTableDef extends TableDef {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 博客用户表
     */
    public static final UserTableDef USER = new UserTableDef();

    /**
     * 用户ID，雪花算法生成
     */
    public final QueryColumn ID = new QueryColumn(this, "id");

    /**
     * 密码加密盐值
     */
    public final QueryColumn SALT = new QueryColumn(this, "salt");

    /**
     * 电子邮箱
     */
    public final QueryColumn EMAIL = new QueryColumn(this, "email");

    /**
     * 手机号码
     */
    public final QueryColumn PHONE = new QueryColumn(this, "phone");

    /**
     * 头像URL地址
     */
    public final QueryColumn AVATAR = new QueryColumn(this, "avatar");

    /**
     * 性别：0-未知 1-男 2-女
     */
    public final QueryColumn GENDER = new QueryColumn(this, "gender");

    /**
     * 账号状态: disabled-禁用, active-正常, locked-锁定
     */
    public final QueryColumn STATUS = new QueryColumn(this, "status");

    /**
     * 出生日期
     */
    public final QueryColumn BIRTHDAY = new QueryColumn(this, "birthday");

    /**
     * 用户昵称，显示用
     */
    public final QueryColumn NICKNAME = new QueryColumn(this, "nickname");

    /**
     * 加密后的密码
     */
    public final QueryColumn PASSWORD = new QueryColumn(this, "password");

    /**
     * 用户名，唯一标识
     */
    public final QueryColumn USERNAME = new QueryColumn(this, "username");

    /**
     * 是否删除: TRUE(1)-已删除, FALSE(0)-未删除
     */
    public final QueryColumn IS_DELETED = new QueryColumn(this, "is_deleted");

    /**
     * 创建时间
     */
    public final QueryColumn CREATE_TIME = new QueryColumn(this, "create_time");

    /**
     * 删除时间
     */
    public final QueryColumn DELETE_TIME = new QueryColumn(this, "delete_time");

    /**
     * 更新时间
     */
    public final QueryColumn UPDATE_TIME = new QueryColumn(this, "update_time");

    /**
     * 最后登录IP
     */
    public final QueryColumn LAST_LOGIN_IP = new QueryColumn(this, "last_login_ip");

    /**
     * 个人简介
     */
    public final QueryColumn INTRODUCTION = new QueryColumn(this, "introduction");

    /**
     * 最后登录时间
     */
    public final QueryColumn LAST_LOGIN_TIME = new QueryColumn(this, "last_login_time");

    /**
     * 所有字段。
     */
    public final QueryColumn ALL_COLUMNS = new QueryColumn(this, "*");

    /**
     * 默认字段，不包含逻辑删除或者 large 等字段。
     */
    public final QueryColumn[] DEFAULT_COLUMNS = new QueryColumn[]{ID, USERNAME, PASSWORD, SALT, NICKNAME, AVATAR, EMAIL, PHONE, GENDER, BIRTHDAY, INTRODUCTION, STATUS, LAST_LOGIN_TIME, LAST_LOGIN_IP, CREATE_TIME, UPDATE_TIME, DELETE_TIME};

    public UserTableDef() {
        super("db_blog", "blog_user");
    }

    private UserTableDef(String schema, String name, String alisa) {
        super(schema, name, alisa);
    }

    public UserTableDef as(String alias) {
        String key = getNameWithSchema() + "." + alias;
        return getCache(key, k -> new UserTableDef("db_blog", "blog_user", alias));
    }

}
